<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      h1 {
        text-align: center;
        margin: 20px 0;
      }
      table {
        width: 500px;
        margin: 0 auto;
        /* 合并单元格边框 */
        border-collapse: collapse;
      }
      th,
      td {
        border: 1px solid #000;
      }
      th,
      td {
        text-align: center;
      }
      th {
        background-color: #ccc;
      }
    </style>
  </head>
  <body>
    <h1>学生列表</h1>
    <table>
      <thead>
        <tr>
          <th>姓名</th>
          <th>年龄</th>
        </tr>
      </thead>
      <tbody>
        <script>
          // 1. 定义数组对象
          const arr = [
            { name: "张三", age: 18 },
            { name: "李四", age: 20 },
            { name: "王五", age: 22 },
          ];
          for (let i = 0; i < arr.length; i++) {
            document.write(`
            <tbody>
              <tr>
                <td>${arr[i].name}</td>
                <td>${arr[i].age}</td>
              </tr>
            </tbody>
          `);
          }
        </script>
      </tbody>
    </table>
  </body>
</html>
